#include "MsgType.h"

int Msg::get_sender_id() const noexcept {
    return sender_id;
}

string Msg::get_chat_room_id() const noexcept {
    return chat_room_id;
}

string Msg::get_time() const noexcept {
    return time;
}

int Msg::getMsgType()const noexcept{
    return type;
}


Msg::Msg(const int&sender_id,const string&chat_room_id,const string&time,const string&data,const int&type){
    this->sender_id=sender_id;
    this->chat_room_id=chat_room_id;
    this->time=time;
    this->data=data;
    this->type=type;
}

json Msg::serializeMsg() const {
    json j;
    try{
    j["sender_id"]=sender_id;
    j["chat_room_id"]=chat_room_id;
    j["time"]=time;
    j["data"]=data;
    j["type"]=type;
    }catch(json::exception& e){
        cerr<<"Msg::serializeMsg error:"<<e.what()<<endl;
        throw e;
    }
    return j;
}


void Msg::unserializeMsg(const json&msg_json){
    try{
        this->sender_id=msg_json["sender_id"];
        this->chat_room_id=msg_json["chat_room_id"];
        this->time=msg_json["time"];
        this->data=msg_json["data"];
        this->type=msg_json["type"];
    }catch(json::exception& e){
        cerr<<"Msg::unserializeMsg error:"<<e.what()<<endl;
        throw e;
    }
    return;
}

